<template>
	<view class=" pb30" style="overflow: hidden;">
		<block v-if="listData.length>0">
		<view class="record-item u-flex u-flex-between u-flex-y-center" v-for="(item,index) in listData" :key="index">
			<view class="l">
				<view class="h">{{item.consumetype}}</view>
				<view class="time">{{item.recdate}}</view>
			</view>
			<view class="r">
				¥{{item.totalmoney}}
			</view>
		</view>
		<!-- <view class="record-item u-flex u-flex-between u-flex-y-center">
			<view class="l">
				<view class="h">充值</view>
				<view class="time">2020.3.5 12:25:23</view>
			</view>
			<view class="r">
				¥300
			</view>
		</view> -->
		<u-loadmore
				marginBottom="50"
		        :status="status" 
		        :loading-text="loadingText" 
		        :loadmore-text="loadmoreText" 
		        :nomore-text="nomoreText" 
		/>
		</block>
		<blcok v-else>
			<u-empty marginTop="100" :text="emptyTips" mode="list"></u-empty>
		</blcok>
		
	</view>
</template>

<script>
	
	export default{
		components:{
			
		},
		data() {
			return {
				listData:[],
				imgUrl:this.imgUrl,
				status: 'loadmore',
				loadingText: '努力加载中',
				loadmoreText: '轻轻上拉',
				nomoreText: '仅显示三个月内的消费记录',
				pageindex:1
			}
		},
		  computed: {
		       
		    },
		onLoad() {
			this.GetICRecord()
		},
		methods: {
			GetICRecord(){
				// var date = new Date();
				// var year = date.getFullYear();    //  返回的是年份
				// var month = date.getMonth() + 1;  //  返回的月份上个月的月份，记得+1才是当月
				// var dates = date.getDate()>9?date.getDate():'0'+date.getDate();       //  返回的是几号
				// var hour = date.getHours()>9?date.getHours():'0'+date.getHours();
				// var minute = date.getMinutes()>9?date.getMinutes():'0'+date.getMinutes();
				// var second = date.getSeconds()>9?date.getSeconds():'0'+date.getSeconds();
				
				// let enddate = year+'-'+month+'-'+dates+' '+hour+':'+minute+':'+second;
				// let startdate = year+'-'+(month-3)+'-'+dates+' '+hour+':'+minute+':'+second;
				 let now = new Date();
				// 获取当前日期的前三个月的月份
				let pastMonth = now.getMonth() - 3;
				// 修改月份，如果前三个月对应没有该日期，则向后延顺
				let startdate = now.setMonth(pastMonth);
				this.status = "loading"
				
				this.$http.GetICRecord({
					enddate:new Date(),
					startdate:new Date(startdate),
					pagesize:20,
					pageindex:this.pageindex,
					cardno:uni.getStorageSync('userInfo').cardNo,
					phoneno:uni.getStorageSync('userInfo').mobile,
					timestamp:String(Date.now())
				}).then(res => {
					if(res.code==0){
					this.status = "loadmore";
					if(res.content.length>0){
						this.listData = this.listData.concat(res.content);
						if(res.content.length<20){
							this.status = "nomore"
						}
					}else{
						this.status = "nomore"
					}
					}
				})
			}
		},
		onReachBottom() {
			this.pageindex ++;
			this.GetICRecord()
		}
	}
</script>

<style lang="scss" scoped>
	.record-item{
		width: 710rpx;height: 120rpx;background: #fff;
		margin: 20rpx auto 0;padding: 20rpx;border-radius: 16rpx;
		.l{
			.h{font-size: 32rpx;color: #222;line-height: 45rpx;}
			.time{color: #888;font-size: 24rpx;line-height: 34rpx;}
		}
		.r{
			font-size: 32rpx;color: #222;
		}
	}

	
</style>